/* 
 * File:   Visualizer.cpp
 * Author: cjjonker
 * 
 * Created on 20 december 2012, 15:06
 */

#include "Visualizer.h"
#include "Simulation.h"

using namespace std;

Visualizer::Visualizer()
:
d_isactive(false),
d_uses_colormap(true),
d_uses_vector_dataset(false),
d_has_multiple_appearances(false),
d_current_map_dataset_index(0),
d_current_vector_dataset_index(0),
d_appearance(0)
{
    
    d_map_dataset_names = {"Fluid Density", "Fluid Velocity", "Force Magnitude", "Grad(Rho) Magnitude", "Grad(V) Magnitude", "Angle V", "Angle F", "Angle Grad(Rho)", "Angle Grad(V)"};
    d_vector_dataset_names = {"Fluid Flow", "Force Field", "Grad(Rho)", "Grad(V)"};
}


void Visualizer::setCurrentVectorDataset()
{
    setCurrentVectorDataset(d_current_vector_dataset_index);
}

void Visualizer::setCurrentVectorDataset(int id)
{
    d_current_vector_dataset_index = id;
    switch(id)
    {
        case Flow:
            d_vector_dataset = d_simulation->getVVectorDataset();                        
            break;
        case Force:
            d_vector_dataset = d_simulation->getFVectorDataset();
            break;
        case GradientRho:
            d_vector_dataset = d_simulation->getGradRhoVectorDataset();
            break;
        case GradientV:
            d_vector_dataset = d_simulation->getGradVVectorDataset();
        default: //default to flow if something unexpected happens.
            d_current_vector_dataset_index = Flow;
            d_vector_dataset = d_simulation->getVVectorDataset();            
    }
}

void Visualizer::setCurrentMapDataset()
{
    setCurrentMapDataset(d_current_map_dataset_index);
}

void Visualizer::setCurrentMapDataset(int id)
{
    d_current_map_dataset_index = id;
    switch(id)
    {
        case Rho:
            d_map_dataset = d_simulation->getRhoDataset();            
            break;
        case V:
            d_map_dataset = d_simulation->getVDataset();
            break;
        case F:
            d_map_dataset = d_simulation->getFDataset();
            break;
        case GradientMagnitudeRho:
            d_map_dataset = d_simulation->getGradRhoDataset();
            break;
        case GradientMagnitudeV:
            d_map_dataset = d_simulation->getGradVDataset();
            break;
        case AngleV:
            d_map_dataset = d_simulation->getVAngleDataset();
            break;
        case AngleF:
            d_map_dataset = d_simulation->getFAngleDataset();
            break;
        case GradientAngleRho:
            d_map_dataset = d_simulation->getGradRhoAngleDataset();
            break;
        case GradientAngleV:
            d_map_dataset = d_simulation->getGradVAngleDataset();
            break;
        default:
            d_current_map_dataset_index = Rho;
            d_map_dataset = d_simulation->getRhoDataset();
            break;
    }
        
}

Visualizer::Visualizer(std::string &name)
: 
d_name(name)
{
    
}

void Visualizer::setColormapMinMax()
{
    d_map.minimum(d_map_dataset->getMin());
    d_map.maximum(d_map_dataset->getMax());
}

void Visualizer::setGLColor(int idx)
{    
    d_map.set(d_map_dataset->getData(idx));
}

void Visualizer::setGLColor(float x, float y)
{
    d_map.set(d_map_dataset->getData(x, y));
}

void Visualizer::init()
{
    setCurrentMapDataset();
    if (d_uses_vector_dataset)
    {
        setCurrentVectorDataset();
    }
}

void Visualizer::setCurrentAppearance(int id)
{
    d_appearance = id;
}


